package egovframework.npqs.pqi.mobile.activity.disinfection;

import java.io.File;
import java.util.ArrayList;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import android.app.Activity;
import android.app.AlertDialog;
import android.app.DatePickerDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Matrix;
import android.graphics.Paint;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.net.Uri;
import android.os.AsyncTask;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.provider.MediaStore;
import android.text.Editable;
import android.text.InputType;
import android.text.TextWatcher;
import android.util.Log;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.View.OnFocusChangeListener;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemSelectedListener;
import android.widget.ArrayAdapter;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.CompoundButton.OnCheckedChangeListener;
import android.widget.DatePicker;
import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.RadioButton;
import android.widget.RelativeLayout;
import android.widget.RelativeLayout.LayoutParams;
import android.widget.Spinner;
import android.widget.TextView;
import android.widget.Toast;
import egovframework.npqs.pqi.mobile.ActivityMain;
import egovframework.npqs.pqi.mobile.AppStatus;
import egovframework.npqs.pqi.mobile.BaseFragment;
import egovframework.npqs.pqi.mobile.R;
import egovframework.npqs.pqi.mobile.activity.CompanySearchActivity;
import egovframework.npqs.pqi.mobile.activity.PlaceOfficerActivity;
import egovframework.npqs.pqi.mobile.activity.approve.ApproveDetail;
import egovframework.npqs.pqi.mobile.jsoncontent.DisinfecResultDetailItem;
import egovframework.npqs.pqi.mobile.jsoncontent.ErrorItem;
import egovframework.npqs.pqi.mobile.jsoncontent.listitem.AntMetCdItem;
import egovframework.npqs.pqi.mobile.jsoncontent.listitem.EquKindItem;
import egovframework.npqs.pqi.mobile.jsoncontent.listitem.MedCdItem;
import egovframework.npqs.pqi.mobile.jsoncontent.listitem.QuarRsltDtailItem;
import egovframework.npqs.pqi.mobile.jsonparser.DisinfectionDetailThread;
import egovframework.npqs.pqi.mobile.jsonparser.DisinfectionDetailThread.DisinfectionDetailThreadCallback;
import egovframework.npqs.pqi.mobile.jsonparser.DisinfectionResultUpdateThread;
import egovframework.npqs.pqi.mobile.jsonparser.DisinfectionResultUpdateThread.DisinfectionResultUpdateThreadCallback;

//소독결과등록
public class DisinfectionResultInsert extends BaseFragment implements
		OnClickListener, DisinfectionDetailThreadCallback,
		OnItemSelectedListener, DisinfectionResultUpdateThreadCallback{
	private AppStatus myapp;
	private Context context;
	private String planSn, recNo, success, dnsfResNo;

	private ImageButton upBtn, downBtn, searchBtn, sCalendarBtn, eCalendarBtn;
	private EditText offCdEdit, requestNumEdit; // 검역신청검역지 코드 에디트 박스, 검역신청 상세번호
												// 에디트 박스

	private ListView listView;
	private DisinfectionDetailListAdapter disinfectionDetailListAdapter;

	private TextView headerTotTxt, navigation;
	private EditText content1_1, content1_2, content3_1;
	private EditText sDateEdit, sDateHEdit, sDateMEdit;
	private EditText eDateEdit, eDateHEdit, eDateMEdit;
	private TextView content2_1, content2_2, content4_1, content4_2;
	private Spinner content6_1, content7_1, content8_1;
	private EditText content6_2, content9_1, content9_2;
	private EditText content10_1, content11_1, content12_2, content13_1, content13_2, edit_request_num;
	private RadioButton chk_Y, chk_N;
	private TextView content12_1;
	private ImageButton companySearchBtn, dosageBtn1, dosageBtn2, openBtn, openBtn2;

	private ArrayList<Integer> selectedArr;

	private DisinfecResultDetailItem disfecResultItem;
	private DisinfectionDetailThread disfecThread;
	private DisinfectionResultUpdateThread disfecUpdateThread;
	private ArrayList<QuarRsltDtailItem> prodArrList;
	private ArrayList<AntMetCdItem> antArrList;
	private ArrayList<EquKindItem> equArrList;
	private ArrayList<MedCdItem> medArrList;

	private ArrayList<String> spinAntArrList, spinEquArrList, spinMedArrList;

	private Button footerBtn01, footerBtn02, footerBtn03, footerBtn04; // 하단 버튼
	
	private boolean firstLoad;
	
	private final static int MSG_QUARANTINE_COMPLETED = 0;
	private final static int MSG_QUARANTINE_ERROR = 1;
	private final static int MSG_NETWORK_ERROR = 2;
	private final static int MSG_QUARANTINE_UPDATE_COMPLETED = 3;
	private final static int MSG_QUARANTINE_UPDATE_ERROR = 4;

	private TextView titleTxt;
	private View view;
	private ImageButton menuBtn, homeBtn;
	private ActivityMain am;
	
	//사진
	private RelativeLayout detail_layout13_1, photo_check_mgs;
	private ImageView photo_view, photo_view2;
	private ImageButton button_13_1, button_13_2;
	private String castString1, castString2;
	private Drawable drawable1, drawable2;
	private String url1, url2;
	
	//하단 리스트 해더
	private LinearLayout list_header_Layout;
	
	/* G-MOBILE 변수*/
    private String temp;
    
    private String mResult;
    
    private String requestNum;
    JSONObject resultData;
	JSONObject resultMaster;
	JSONObject resultDetail;
	
	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {
		AppStatus.navigation.addPathLocation("소독결과등록");
		castString1="";
		castString2="";
		firstLoad=true;
		disfecResultItem = new DisinfecResultDetailItem();
		if (view != null) {
			ViewGroup parent = (ViewGroup) view.getParent();
			if (parent != null)
				parent.removeView(view);
		} else {
			view = inflater.inflate(R.layout.activity_disinfection_detail,
					container, false);
			init();
		}

		return view;
	}

	private void init() {
		context = view.getContext();
		myapp = (AppStatus) context.getApplicationContext();
		myapp.startBroker(context);
		am = (ActivityMain) ActivityMain.am;
		
		//하단 리스트 해더
		list_header_Layout = (LinearLayout)view.findViewById(R.id.list_header_Layout);
		
		homeBtn = (ImageButton) view.findViewById(R.id.btnHome);
		homeBtn.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				getActivity().onBackPressed();
			}
		});

		menuBtn = (ImageButton) view.findViewById(R.id.btnLeftMenu);
		menuBtn.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				am.toggle();
			}
		});

		/*loginBtn = (ImageButton) view.findViewById(R.id.btnLogin);
		loginBtn.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				myapp.appFinish(context);
			}
		});*/

		selectedArr = new ArrayList<Integer>();

		titleTxt = (TextView) view.findViewById(R.id.headerTitleText);
		titleTxt.setText("소독결과등록");
		
		navigation = (TextView)view.findViewById(R.id.navigation);
		navigation.setText(AppStatus.navigation.getPath());
		Log.i("AppStatus.navigation.getPath()->", AppStatus.navigation.getPath());

		offCdEdit = (EditText) view.findViewById(R.id.edit_offcd);
		offCdEdit.setText(myapp.getLoginItem().getOffCd());

		requestNumEdit = (EditText) view.findViewById(R.id.edit_request_num);

		searchBtn = (ImageButton) view.findViewById(R.id.search_btn);
		searchBtn.setOnClickListener(this);

		listView = (ListView) view.findViewById(R.id.dis_detail_list);
		listView.setVisibility(View.GONE);
		disinfectionDetailListAdapter = new DisinfectionDetailListAdapter();

		footerBtn01 = (Button) view.findViewById(R.id.footer01Btn);
		footerBtn02 = (Button) view.findViewById(R.id.footer02Btn);
		footerBtn03 = (Button) view.findViewById(R.id.footer03Btn);
		footerBtn04 = (Button) view.findViewById(R.id.footer04Btn);

		companySearchBtn = (ImageButton) view.findViewById(R.id.company_search_btn);
		content1_1 = (EditText) view.findViewById(R.id.content_1_1);
		content1_2 = (EditText) view.findViewById(R.id.content_1_2);
		content2_1 = (TextView) view.findViewById(R.id.content_2_1);
		content2_2 = (TextView) view.findViewById(R.id.content_2_2);
		content3_1 = (EditText) view.findViewById(R.id.content_3_1);
		content4_1 = (TextView) view.findViewById(R.id.content_4_1);
		content4_2 = (TextView) view.findViewById(R.id.content_4_2);
		edit_request_num = (EditText) view.findViewById(R.id.edit_request_num); // 검역신청번호
																				// 뒷자리
		sDateEdit = (EditText) view.findViewById(R.id.edit_sdate);
		sDateHEdit = (EditText) view.findViewById(R.id.edit_s_time_s);
		sDateMEdit = (EditText) view.findViewById(R.id.edit_s_time_e);
		sCalendarBtn = (ImageButton) view.findViewById(R.id.btn_s_calender);
		eDateEdit = (EditText) view.findViewById(R.id.edit_edate);
		eDateHEdit = (EditText) view.findViewById(R.id.edit_e_time_s);
		eDateMEdit = (EditText) view.findViewById(R.id.edit_e_time_e);
		eCalendarBtn = (ImageButton) view.findViewById(R.id.btn_e_calender);
		content6_1 = (Spinner) view.findViewById(R.id.content_6_1);
		content6_2 = (EditText) view.findViewById(R.id.content_6_2);
		content7_1 = (Spinner) view.findViewById(R.id.content_7_1);
		content8_1 = (Spinner) view.findViewById(R.id.content_8_1);
		content9_1 = (EditText) view.findViewById(R.id.content_9_1);
		content9_2 = (EditText) view.findViewById(R.id.content_9_2);
		content10_1 = (EditText) view.findViewById(R.id.content_10_1);
		content11_1 = (EditText) view.findViewById(R.id.content_11_1);
		chk_Y = (RadioButton) view.findViewById(R.id.chk_y);
		chk_N = (RadioButton) view.findViewById(R.id.chk_n);
		content12_1 = (TextView) view.findViewById(R.id.content_12_1);
		content12_2 = (EditText) view.findViewById(R.id.content_12_2);
		content13_1 = (EditText) view.findViewById(R.id.content_13_1);
		content13_2 = (EditText) view.findViewById(R.id.content_13_2);
		
		// 현장검역관
		dosageBtn1 = (ImageButton) view.findViewById(R.id.dosage_plus_btn1);
		dosageBtn2 = (ImageButton) view.findViewById(R.id.dosage_plus_btn2);
		openBtn = (ImageButton) view.findViewById(R.id.open_plus_btn);
		openBtn2 = (ImageButton) view.findViewById(R.id.open_plus_btn2);

		sDateEdit.setInputType(InputType.TYPE_NULL);
		eDateEdit.setInputType(InputType.TYPE_NULL);

		sDateEdit.setOnFocusChangeListener(new OnFocusChangeListener() {
			@Override
			public void onFocusChange(View v, boolean hasFocus) {
				myapp.utilm.InputKeybordHidden(context, sDateEdit);
			}
		});

		eDateEdit.setOnFocusChangeListener(new OnFocusChangeListener() {
			@Override
			public void onFocusChange(View v, boolean hasFocus) {
				myapp.utilm.InputKeybordHidden(context, eDateEdit);
			}
		});

		//사진
		detail_layout13_1 = (RelativeLayout) view.findViewById(R.id.detail_layout13_1);
		photo_check_mgs = (RelativeLayout) view.findViewById(R.id.photo_check_mgs);
		photo_view = (ImageView) view.findViewById(R.id.photo_view);
		photo_view2 = (ImageView) view.findViewById(R.id.photo_view2);
		button_13_1 = (ImageButton) view.findViewById(R.id.button_13_1);
		button_13_2 = (ImageButton) view.findViewById(R.id.button_13_2);
		castString1="";
		castString2="";

		// 연락처 누르면 전화걸기
		content2_2.setPaintFlags(content2_2.getPaintFlags()
				| Paint.UNDERLINE_TEXT_FLAG);
		content2_2.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				Uri n = Uri.parse("tel: " + content2_2.getText());
				startActivity(new Intent(Intent.ACTION_DIAL, n));
			}
		});
		
		LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);

		companySearchBtn.setOnClickListener(this);
		sCalendarBtn.setOnClickListener(this);
		eCalendarBtn.setOnClickListener(this);
		dosageBtn1.setOnClickListener(this);
		dosageBtn2.setOnClickListener(this);
		openBtn.setOnClickListener(this);
		openBtn2.setOnClickListener(this);
		//footerBtn01.setOnClickListener(this);
		footerBtn04.setOnClickListener(this);
		
		//요청에 의해 없앤다..
		footerBtn01.setBackgroundResource(R.drawable.f_blank_sel);
		//에러나면 버튼막기
		footerBtn02.setBackgroundResource(R.drawable.f_blank_sel);
		footerBtn03.setBackgroundResource(R.drawable.f_blank_sel);
		//사진막기
		//footerBtn04.setBackgroundResource(R.drawable.f_blank_sel);
		
	}

	private void searchDetail(String requestNum) {
		myapp.showDialogNo(context);
		this.requestNum = requestNum;
		temp = "조건검색";
		list_header_Layout.setVisibility(View.VISIBLE);
		myapp.utilm.InputKeybordHidden(context, offCdEdit);
		myapp.utilm.InputKeybordHidden(context, requestNumEdit);
		//asyncTaskIsConnectedVPN();
		threadStart();
	}
	
	private void searchDetailAfterSave(String requestNum){
		myapp.showDialogNo(context);
		this.requestNum = requestNum;
		temp = "저장검색";
		myapp.utilm.InputKeybordHidden(context, requestNumEdit);
		myapp.utilm.InputKeybordHidden(context, offCdEdit);
		//asyncTaskIsConnectedVPN();
		threadStart();
	}
	
	public void threadStart(){
		if("조건검색".equals(temp)){
    		disfecThread = new DisinfectionDetailThread(context, this, "", requestNum, true, AppStatus.getmUserId());
    		disfecThread.start();
    	}
    	if("저장검색".equals(temp)){
    		disfecThread = new DisinfectionDetailThread(context, this, planSn, requestNum, false, AppStatus.getmUserId());
    		disfecThread.start();
    	}
    	if("저장".equals(temp)){
    		disfecUpdateThread = new DisinfectionResultUpdateThread(context, this,
    				resultData.toString(), resultDetail.toString(), AppStatus.getmUserId());
    		disfecUpdateThread.start();
    	}
	}

	private void layoutSetting() {
		
		offCdEdit.setText(disfecResultItem.getOffCd());
		requestNumEdit.setText(disfecResultItem.getRecNo());
		content1_1.setText(disfecResultItem.getEntrpsUnitySn());
		content1_2.setText(disfecResultItem.getCprNm());
		content2_1.setText(disfecResultItem.getEmpNm());
		content2_2.setText(disfecResultItem.getTelNo());
		content3_1.setText(disfecResultItem.getDsnfInspctPlace());
		content4_1.setText(disfecResultItem.getMdctStackCnt());
		content4_2.setText(disfecResultItem.getMdctTotPrdlstQy());
		sDateEdit.setText(disfecResultItem.getMdctDe());
		sDateHEdit.setText(disfecResultItem.getMdctHh());
		sDateMEdit.setText(disfecResultItem.getMdctMi());
		eDateEdit.setText(disfecResultItem.getOpnDe());
		eDateHEdit.setText(disfecResultItem.getOpnHh());
		eDateMEdit.setText(disfecResultItem.getOpnMi());
		content6_2.setText(disfecResultItem.getAntMin());
		
		//단위역량, 고내온도, 훈증방법, 훈증용적
		//content_9_1, content_9_2, content_10_1, content_11_1
		content9_1.setText(disfecResultItem.getMedQty());
		content9_2.setText(disfecResultItem.getRooTemp());
		content10_1.setText(disfecResultItem.getAntMet());
		content11_1.setText(disfecResultItem.getFumQty());
		
		//사진보기
		if("".equals(disfecResultItem.getImgResult1().trim())){
			url1="";
			castString1="";
		}else{
			url1 = myapp.cameraUtil.photoSetting(disfecResultItem.getImgResult1()).replace("\\", "/");
			new yourTask().execute();
		}
		if("".equals(disfecResultItem.getImgResult2().trim())){
			url2 = "";
			castString2="";
		}else{
			url2 = myapp.cameraUtil.photoSetting(disfecResultItem.getImgResult2()).replace("\\", "/");
			new yourTask().execute();
		}
		button_13_1.setOnClickListener(this);
		button_13_2.setOnClickListener(this);
		
		if(firstLoad){
			if(disfecResultItem.getOpeNamNm1().equals("")){
				content13_1.setText(myapp.getLoginItem().getUserNm());
				disfecResultItem.setOpeNamCd1(myapp.getLoginItem().getUserSn());
			}else{
				content13_1.setText(disfecResultItem.getOpeNamNm1());
			}
			content12_1.setText(disfecResultItem.getMedNamNm1());
			content12_2.setText(disfecResultItem.getMedNamNm2());
			content13_2.setText(disfecResultItem.getOpeNamNm2());
			
			firstLoad=false;
		}
		content13_1.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				content13_1.setText("");
			}
		});
		content13_2.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				content13_2.setText("");
			}
		});
		content12_1.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				content12_1.setText("");
			}
		});
		content12_2.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				content12_2.setText("");
			}
		});
		
		if (disfecResultItem.getRotDiv().equals("N")) {
			chk_Y.setChecked(false);
			chk_N.setChecked(true);
		} else {
			chk_Y.setChecked(true);
			chk_N.setChecked(false);
		}

		listView.setVisibility(View.VISIBLE);
		antArrList = disfecResultItem.getAntMetCdList();
		if (antArrList.size() > 0) {
			spinAntArrList = new ArrayList<String>();
			for (int i = 0; i < antArrList.size(); i++) {
				spinAntArrList.add(antArrList.get(i).getCodeNm());
			}
		}
		medArrList = disfecResultItem.getMedCdList();
		if (medArrList.size() > 0) {
			spinMedArrList = new ArrayList<String>();
			for (int i = 0; i < medArrList.size(); i++) {
				spinMedArrList.add(medArrList.get(i).getCodeNm());
			}
		}
		equArrList = disfecResultItem.getEquKindList();
		if (equArrList.size() > 0) {
			spinEquArrList = new ArrayList<String>();
			for (int i = 0; i < equArrList.size(); i++) {
				spinEquArrList.add(equArrList.get(i).getCodeNm());
			}
		}

		ArrayAdapter<String> antAdapter = new ArrayAdapter<String>(context,
				R.layout.spinner_item, spinAntArrList);

		ArrayAdapter<String> medAdapter = new ArrayAdapter<String>(context,
				R.layout.spinner_item, spinMedArrList);

		ArrayAdapter<String> equAdapter = new ArrayAdapter<String>(context,
				R.layout.spinner_item, spinEquArrList);

		antAdapter.setDropDownViewResource(R.layout.spinner_item);
		medAdapter.setDropDownViewResource(R.layout.spinner_item);
		equAdapter.setDropDownViewResource(R.layout.spinner_item);

		content6_1.setAdapter(antAdapter);
		content7_1.setAdapter(equAdapter);
		content8_1.setAdapter(medAdapter);

		for (int i = 0; i < antArrList.size(); i++) {
			if (antArrList.get(i).getCode().equals(disfecResultItem.getAntMetCd())) {
				content6_1.setSelection(i);
			}
		}
		
		for (int i = 0; i < equArrList.size(); i++) {
			if (equArrList.get(i).getCode().equals(disfecResultItem.getEquKind())) {
				content7_1.setSelection(i);
			}
		}

		for (int i = 0; i < medArrList.size(); i++) {
			if (medArrList.get(i).getCode().equals(disfecResultItem.getMedCd())) {
				content8_1.setSelection(i);
			}
		}
		
		footerBtn02.setOnClickListener(this);
		footerBtn03.setOnClickListener(this);
		footerBtn02.setBackgroundResource(R.drawable.foot_save_selector);
		footerBtn03.setBackgroundResource(R.drawable.foot_approval_selector);

		content6_1.setOnItemSelectedListener(this);
		content7_1.setOnItemSelectedListener(this);
		content8_1.setOnItemSelectedListener(this);

		prodArrList = disfecResultItem.getItems();

		headerTotTxt = (TextView) view.findViewById(R.id.header_tot);
		upBtn = (ImageButton) view.findViewById(R.id.header_up_btn);
		downBtn = (ImageButton) view.findViewById(R.id.header_down_btn);

		headerTotTxt.setText("총 품목:" + disfecResultItem.getItemsResult() + "건");

		listView.setAdapter(disinfectionDetailListAdapter);

		listView.setVisibility(View.VISIBLE);

		upBtn.setOnClickListener(this);
		downBtn.setOnClickListener(this);
		downBtn.performClick();

	}
	
	private class yourTask extends AsyncTask<Integer, Void, Integer> {
	    @Override
	    protected void onPreExecute() {
	        super.onPreExecute();
	        //show a progress bar
	    }

	    @Override
	    protected Integer doInBackground(Integer... params) {
	        BitmapDrawable drawable = null;
	        Bitmap bitmap = null;
	        if(!"".equals(url1)){
	        	drawable1  =  myapp.cameraUtil.LoadImageFromWeb(url1);
	        	drawable = (BitmapDrawable)drawable1;
	        	bitmap = drawable.getBitmap();
	        	castString1 = myapp.cameraUtil.castByteArrayToString(myapp.cameraUtil.bitmapToByteArray(bitmap));
	        }
	        if(!"".equals(url2)){
	        	drawable2  =  myapp.cameraUtil.LoadImageFromWeb(url2); 
	        	drawable = (BitmapDrawable)drawable2;
	        	bitmap = drawable.getBitmap();
	        	castString2 = myapp.cameraUtil.castByteArrayToString(myapp.cameraUtil.bitmapToByteArray(bitmap));
	        }
	        return 0; 
	    }      

	    @Override
	    protected void onPostExecute(Integer result) {
	        super.onPostExecute(result);
	        if(!"".equals(castString1.trim())){
	        	detail_layout13_1.setVisibility(View.VISIBLE);
	        	photo_check_mgs.setVisibility(View.GONE);
	        	photo_view.setVisibility(View.VISIBLE);
	        	photo_view.setImageDrawable(drawable1);   
	 	        button_13_1.setVisibility(View.VISIBLE);
	        }
	        if(!"".equals(castString2.trim())){
	        	photo_view2.setVisibility(View.VISIBLE);
	        	photo_view2.setImageDrawable(drawable2);
	 	        button_13_2.setVisibility(View.VISIBLE);
	        }
	    }
	}
	
	// 첨부된 이미지뷰를 체크하여 둘다 없으면 레이아웃을 지운다.
	private void layoutCheck(ImageView v1, ImageView v2) {
		if (v1.getDrawable() == null && v2.getDrawable() == null) {
			detail_layout13_1.setVisibility(View.GONE);
			photo_check_mgs.setVisibility(View.VISIBLE);
		}
	}
	
	private void disfinfectionSave() {
		myapp.startBroker(context);
		
		resultDetail = new JSONObject();
		resultData = new JSONObject();
		resultMaster = new JSONObject();
		JSONArray requestArray = new JSONArray();
		JSONObject obj;
		
		for (int i = 0; i < selectedArr.size(); i++) {
			/*int value = selectedArr.get(i);
			View v = disinfectionDetailListAdapter.getView(value, null,
					listView);
			EditText editText = (EditText) v.findViewById(R.id.detail_prod_cnt);*/
			try {
				obj = new JSONObject();
				obj.put("offCd", prodArrList.get(i).getOffCd());
				obj.put("recNo", prodArrList.get(i).getRecNo());
				obj.put("dsnfResOffCd", prodArrList.get(i).getDsnfResOffCd());
				obj.put("dsnfResNo", prodArrList.get(i).getDsnfResNo());
				obj.put("antQty", prodArrList.get(i).getAntQty());
				obj.put("resSeq", prodArrList.get(i).getRecSeq());
				obj.put("insQty", prodArrList.get(i).getInsQty());
				obj.put("qunCd", prodArrList.get(i).getQunCd());
				obj.put("dsnfCmmndNo", prodArrList.get(i).getDsnfCmmndNo());
				obj.put("updNamCd", myapp.getLoginItem().getUserSn());
				obj.put("antMetCd", disfecResultItem.getAntMetCd());
				requestArray.put(obj);
			} catch (JSONException e) {
				e.printStackTrace();
			}
		}

		try {
			resultMaster.put("entrpsUnitSn", content1_1.getText().toString());
			resultMaster.put("dsnfInspctPlace", content3_1.getText().toString());
			resultMaster.put("mdctDe", sDateEdit.getText().toString());
			resultMaster.put("mdctHh", sDateHEdit.getText().toString());
			resultMaster.put("mdctMi", sDateMEdit.getText().toString());
			resultMaster.put("openDe", eDateEdit.getText().toString());
			resultMaster.put("openHh", eDateHEdit.getText().toString());
			resultMaster.put("openMi", eDateMEdit.getText().toString());
			resultMaster.put("antMin", content6_2.getText().toString());
			resultMaster.put("antMetCd", disfecResultItem.getAntMetCd());
			resultMaster.put("equKind", disfecResultItem.getEquKind());
			resultMaster.put("medQty", content9_1.getText().toString());
			resultMaster.put("antMet", content10_1.getText().toString());
			resultMaster.put("fumQty", content11_1.getText().toString());
			resultMaster.put("updNamCd", myapp.getLoginItem().getUserSn());
			if (chk_Y.isChecked()) {
				resultMaster.put("rotDiv", "Y");
			} else {
				resultMaster.put("rotDiv", "N");
			}
			resultMaster.put("rooTemp", content9_2.getText().toString());
			resultMaster.put("medNamCd1", disfecResultItem.getMedNamCd1());
			resultMaster.put("medNamCd2", disfecResultItem.getMedNamCd2());
			resultMaster.put("opeNamCd1", disfecResultItem.getOpeNamCd1());
			resultMaster.put("opeNamCd2", disfecResultItem.getOpeNamCd2());
			resultMaster.put("medCd", disfecResultItem.getMedCd());
			//사진
			if(castString1.equals("")&&!castString2.equals("")){
				castString1=castString2;
				castString2="";
				button_13_2.performClick();
			}
	        resultMaster.put("imgResult1", castString1);
			resultMaster.put("imgResult2", castString2);
			resultMaster.put("fileId", disfecResultItem.getFileId());

			resultData.put("resultMaster", resultMaster);
			resultDetail.put("resultDetail", requestArray);
		} catch (JSONException e) {
			e.printStackTrace();
		}

		myapp.showDialogNo(context);
		temp = "저장";
		//asyncTaskIsConnectedVPN();
		threadStart();

	}

	@Override
	public void onClick(View v) {
		Intent intent;
		switch (v.getId()) {

		case R.id.search_btn:
			if (edit_request_num.getText().toString().length() == 8) {
				searchDetail(offCdEdit.getText().toString() + "-"
						+ requestNumEdit.getText().toString());
			} else {
				myapp.utilm.ShowDialog(context, "실패",
						"검역신청 번호 뒤 8자리를 입력해 주세요.", 20);
			}
			break;

		case R.id.footer01Btn: // 목록 버튼
			getActivity().onBackPressed();
			break;

		case R.id.footer02Btn: // 저장 버튼
			//필수 입력 사항 유효성검사
			//방제업체 : content1_1, content1_2 실시기간 : sDateEdit, sDateHEdit, sDateMEdit,  eDateEdit, eDateHEdit, eDateMEdit
			//소독방법 : content6_1(스피너), 시설종류(스피너) : content7_1 약제/단위(스피너) : content8_1
			if("".equals(content1_1.getText().toString())){
				myapp.utilm.ShowDialog(context, "실패", "방제업체를 검색 해주세요.", 20);
				return;
			}
			if("".equals(content1_2.getText().toString())){
				myapp.utilm.ShowDialog(context, "실패", "방제업체를 검색 해주세요.", 20);
				return;
			}	
			if("".equals(sDateEdit.getText().toString())){
				myapp.utilm.ShowDialog(context, "실패", "실시기간을 입력 해주세요.", 20);
				return;
			}
			if("".equals(sDateHEdit.getText().toString())){
				myapp.utilm.ShowDialog(context, "실패", "실시기간을 입력 해주세요.", 20);
				return;
			}
			if("".equals(sDateMEdit.getText().toString())){
				myapp.utilm.ShowDialog(context, "실패", "실시기간을 입력 해주세요.", 20);
				return;
			}
			if("".equals(eDateEdit.getText().toString())){
				myapp.utilm.ShowDialog(context, "실패", "실시기간을 입력 해주세요.", 20);
				return;
			}
			if("".equals(eDateHEdit.getText().toString())){
				myapp.utilm.ShowDialog(context, "실패", "실시기간을 입력 해주세요.", 20);
				return;
			}
			if("".equals(eDateMEdit.getText().toString())){
				myapp.utilm.ShowDialog(context, "실패", "실시기간을 입력 해주세요.", 20);
				return;
			}
			if(null==content6_1.getSelectedItem()){
				myapp.utilm.ShowDialog(context, "실패", "소독방법을 선택 해주세요.", 20);
				return;
			}
			if(null==content7_1.getSelectedItem()){
				myapp.utilm.ShowDialog(context, "실패", "시설종류를 선택 해주세요.", 20);
				return;
			}
			if(null==content8_1.getSelectedItem()){
				myapp.utilm.ShowDialog(context, "실패", "약제/단위를 선택 해주세요.", 20);
				return;
			}
			
			double antQty= 0.0;
			double insQty= 0.0;
			for(int i=0; i<prodArrList.size(); i++){
				if(prodArrList.get(i).getAntQty().trim().equals("")||prodArrList.get(i).getAntQty().toString()==null){
					myapp.utilm.ShowDialog(context, "실패", "소독수량을 넣으세요.", 20);
					return;
				}
				antQty = Double.parseDouble((prodArrList.get(i).getAntQty()).replace(",", ""));
				insQty = Double.parseDouble((prodArrList.get(i).getInsQty()).replace(",", ""));
				if(antQty>insQty){
					myapp.utilm.ShowDialog(context, "실패", "소독수량은 검역수량보다 많을 수 없습니다.", 20);
					return;
				}
			}
			
			if (selectedArr.size() == 0) {
				myapp.utilm.ShowDialog(context, "실패", "저장하실 품목을 하나라도 선택해주세요.",
						20);
				return;
			} else {
				disfinfectionSave();
			}
			break;

		case R.id.footer03Btn: // 검역결과등록 버튼
			if (selectedArr.size() == 0) {
				myapp.utilm.ShowDialog(context, "실패", "결재하실 품목을 하나라도 선택해주세요.", 20);
				return;
			}else{
				if(!prodArrList.get(selectedArr.get(0)).getDsnfResNo().equals("")){
					for(int i=0; i<prodArrList.size(); i++){
						if(prodArrList.get(i).getSanctnYn().equals("N")){
							myapp.utilm.ShowDialog(context, "실패", "전량소독이 완료된 경우에만 결재 할 수 있습니다.", 20);
							return;
						}
					}
					if(prodArrList.get(selectedArr.get(0)).getDocScrtySe().equals("Y")) {
						moveApprove();
					} else {
						new AlertDialog.Builder(context)
								.setTitle("실패")
								.setMessage(
										"서류미보완 상태입니다. 결재시 서류보완도 완료됩니다.그래도 결재하시겠습니까?")
								.setPositiveButton("확인",
										new DialogInterface.OnClickListener() {
											@Override
											public void onClick(
													DialogInterface dialog,
													int which) {
												try {
													moveApprove();
													dialog.dismiss();
												} catch (Exception e) {
												}
											}
										})
								.setNegativeButton("취소",
										new DialogInterface.OnClickListener() {
											@Override
											public void onClick(
													DialogInterface dialog,
													int which) {
												dialog.dismiss();
											}
										}).setCancelable(false).show();
					}
				} else {
					myapp.utilm
							.ShowDialog(context, "실패", "저장후 결재하실수 있습니다.", 20);
					return;
				}
			}
			break;

		case R.id.footer04Btn: //사진
			if(!castString1.trim().equals("") && !castString2.trim().equals("")){
				myapp.utilm.ShowDialog(context, "실패", "사진은 2장 까지 가능 합니다.", 20);
			}else{
				intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
				intent.putExtra(android.provider.MediaStore.EXTRA_OUTPUT, Uri.fromFile(new File("/sdcard/image.jpg")));
				startActivityForResult(intent, 6);
			}
			break;
			
		case R.id.button_13_1:
			photo_view.setImageDrawable(null);
			photo_view.setVisibility(View.GONE);
			button_13_1.setVisibility(View.GONE);
			castString1="";
			url1="";
			layoutCheck(photo_view, photo_view2);
			break;
			
		case R.id.button_13_2:
			photo_view2.setImageDrawable(null);
			photo_view2.setVisibility(View.GONE);
			button_13_2.setVisibility(View.GONE);
			castString2="";
			url2="";
			layoutCheck(photo_view, photo_view2);
			break;
			
		case R.id.header_up_btn:
			RelativeLayout.LayoutParams listParams = new RelativeLayout.LayoutParams(
					LayoutParams.WRAP_CONTENT, myapp.utilm.getDpToPixel(context, 400));
			listParams.addRule(RelativeLayout.ABOVE, R.id.bottom_layout);
			listView.setLayoutParams(listParams);
			break;
		case R.id.header_down_btn:
			RelativeLayout.LayoutParams listParams1 = new RelativeLayout.LayoutParams(
					LayoutParams.WRAP_CONTENT, myapp.utilm.getDpToPixel(context, 145));
			listParams1.addRule(RelativeLayout.ABOVE, R.id.bottom_layout);
			listView.setLayoutParams(listParams1);
			break;

		case R.id.open_plus_btn: // 현장검역관 +이미지버튼 누르면
			Intent intent01 = new Intent(getActivity().getApplicationContext(),
					PlaceOfficerActivity.class);
			intent01.putExtra("userNm", content13_1.getText().toString());
			startActivityForResult(intent01, 1);
			break;

		case R.id.open_plus_btn2: // 현장검역관 +이미지버튼 누르면
			Intent intent05 = new Intent(getActivity().getApplicationContext(),
					PlaceOfficerActivity.class);
			intent05.putExtra("userNm", content13_2.getText().toString());
			startActivityForResult(intent05, 5);
			break;

		case R.id.dosage_plus_btn1: // 현장검역관 +이미지버튼 누르면
			Intent intent02 = new Intent(getActivity().getApplicationContext(),
					PlaceOfficerActivity.class);
			intent02.putExtra("userNm", content12_1.getText().toString());
			startActivityForResult(intent02, 2);
			break;

		case R.id.dosage_plus_btn2: // 현장검역관 +이미지버튼 누르면
			Intent intent03 = new Intent(getActivity().getApplicationContext(),
					PlaceOfficerActivity.class);
			intent03.putExtra("userNm", content12_2.getText().toString());
			startActivityForResult(intent03, 3);
			break;

		case R.id.btn_s_calender:
			if (!sDateEdit.getText().toString().equals("")) {
				sDateSetting();
			}

			break;

		case R.id.btn_e_calender:
			if (!eDateEdit.getText().toString().equals("")) {
				eDateSetting();
			}
			break;

		case R.id.company_search_btn:
			searchCompany();
			break;

		default:
			break;
		}
	}

	private void moveApprove() {
		Log.i("after approve -myapp.isDataLoadState()", myapp.isDataLoadState()+"");
		Intent intent = new Intent(context, ApproveDetail.class);

		Log.i("size", "size = " + selectedArr.size());
		if (selectedArr.size() == 1) {
			intent.putExtra("resNo", prodArrList.get(selectedArr.get(0))
					.getResNo());
			intent.putExtra("resOffCd", prodArrList.get(selectedArr.get(0))
					.getResOffCd());
			intent.putExtra("value", "0");
		} else {
			String fullResNo = "";
			for (int i = 0; i < selectedArr.size(); i++) {
				if (fullResNo.equals("")) {
					fullResNo = prodArrList.get(selectedArr.get(i)).getResOffCd()
							+ "-"
							+ prodArrList.get(selectedArr.get(i)).getResNo();
				} else {
					fullResNo += ","
							+ prodArrList.get(selectedArr.get(i)).getResOffCd()
							+ "-"
							+ prodArrList.get(selectedArr.get(i)).getResNo();
				}
			}
			intent.putExtra("fullResNo", fullResNo);
			intent.putExtra("value", "1");
		}
		startActivity(intent);
	}

	private void searchCompany() {
		String code = "";
		// 업체명을 검색 팝업 띄우고 업체코드는 리드온리
		/*
		 * if(!content1_1.getText().toString().equals("") &&
		 * !content1_2.getText().toString().equals("")){ code =
		 * prodCdEdit.getText().toString(); }else{
		 * if(!prodNameEdit.getText().toString().equals("")){ code =
		 * prodNameEdit.getText().toString(); }else{ code =
		 * prodCdEdit.getText().toString(); } }
		 */
		Intent intent = new Intent(getActivity().getApplicationContext(),CompanySearchActivity.class);
		//intent.putExtra("cprNm", content1_2.getText().toString());
		intent.putExtra("cprNm", "");
		startActivityForResult(intent, 4);
	}

	private void sDateSetting() {
		String str = sDateEdit.getText().toString();
		int sYear, sDay, sMonth;

		sYear = Integer.parseInt(str.substring(0, 4));
		sMonth = Integer.parseInt(str.substring(5, 7)) - 1;
		sDay = Integer.parseInt(str.substring(8, 10));

		DatePickerDialog dpd = new DatePickerDialog(context,
				new DatePickerDialog.OnDateSetListener() {

					@Override
					public void onDateSet(DatePicker view, int year,
							int monthOfYear, int dayOfMonth) {
						String months = "";
						String days = "";
						if (String.valueOf(monthOfYear + 1).length() == 1) {
							months = "0" + (monthOfYear + 1);
						} else {
							months = String.valueOf((monthOfYear + 1));
						}

						if (String.valueOf(dayOfMonth).length() == 1) {
							days = "0" + dayOfMonth;
						} else {
							days = String.valueOf(dayOfMonth);
						}

						sDateEdit.setText(year + "-" + months + "-" + days);

					}
				}, sYear, sMonth, sDay);
		dpd.show();
	}

	private void eDateSetting() {
		String str = eDateEdit.getText().toString();
		int eYear, eDay, eMonth;

		eYear = Integer.parseInt(str.substring(0, 4));
		eMonth = Integer.parseInt(str.substring(5, 7)) - 1;
		eDay = Integer.parseInt(str.substring(8, 10));

		DatePickerDialog dpd = new DatePickerDialog(context,
				new DatePickerDialog.OnDateSetListener() {

					@Override
					public void onDateSet(DatePicker view, int year,
							int monthOfYear, int dayOfMonth) {
						String months = "";
						String days = "";

						if (String.valueOf(monthOfYear + 1).length() == 1) {
							months = "0" + (monthOfYear + 1);
						} else {
							months = String.valueOf((monthOfYear + 1));
						}

						if (String.valueOf(dayOfMonth).length() == 1) {
							days = "0" + dayOfMonth;
						} else {
							days = String.valueOf(dayOfMonth);
						}

						eDateEdit.setText(year + "-" + months + "-" + days);

					}
				}, eYear, eMonth, eDay);
		dpd.show();
	}

	@Override
	public void OnDisinfectionDetailCompleted(boolean isNetworkConntected,
			DisinfecResultDetailItem quarantineItem, String message) {
		Log.i("message-->", "message-->"+message);
		if(null != message && !"".equals(message)){
			mResult = message;
			reesultToast();
		}
		
		if (myapp.dialog != null && myapp.dialog.isShowing()) {
			myapp.dialog.dismiss();
		}

		if (!isNetworkConntected) { // 네트워크 접속이 되어 있지 않을 때
			Message msg = handler.obtainMessage();
			msg.what = MSG_NETWORK_ERROR;
			handler.sendMessage(msg);
			return;
		}

		if (quarantineItem != null) {
			this.disfecResultItem = quarantineItem;
			Message msg = handler.obtainMessage();
			msg.what = MSG_QUARANTINE_COMPLETED;
			handler.sendMessage(msg);
		}

	}

	@Override
	public void OnDisinfectionDetailError(ErrorItem errorItem) {
		if (myapp.dialog != null && myapp.dialog.isShowing()) {
			myapp.dialog.dismiss();
		}
		
		Message msg = handler.obtainMessage();
		msg.what = MSG_QUARANTINE_ERROR;
		if (errorItem != null) {
			msg.obj = errorItem.getrDesc();
		}
		handler.sendMessage(msg);

	}

	private Handler handler = new Handler() {
		@Override
		public void handleMessage(final Message msg) {
			switch (msg.what) {
			case MSG_QUARANTINE_COMPLETED:
				layoutSetting();
				break;

			case MSG_QUARANTINE_ERROR:
				String errMsg = "";
				if (msg == null || msg.obj.toString().equals("")) {
					errMsg = "서버와의 연결에 실패하였습니다.";
				} else {
					errMsg = msg.obj.toString();
				}

				//에러나면 버튼막기
				footerBtn02.setBackgroundResource(R.drawable.foot_blank_selector);
				footerBtn03.setBackgroundResource(R.drawable.foot_blank_selector);
				footerBtn02.setClickable(false);
				footerBtn03.setClickable(false);
				
				listView.setVisibility(View.GONE);
				myapp.utilm.ShowDialog(context, "실패", errMsg, 20);

				break;

			case MSG_NETWORK_ERROR:
				myapp.utilm.ShowDialog(context, "실패", "네트워크에러", 20);
				break;
			case MSG_QUARANTINE_UPDATE_COMPLETED:
				new AlertDialog.Builder(context)
						.setTitle("저장")
						.setMessage(success)
						.setPositiveButton("확인",
								new DialogInterface.OnClickListener() {

									@Override
									public void onClick(DialogInterface dialog,
											int which) {
										try {
											searchDetailAfterSave(dnsfResNo);
										} catch (Exception e) {

										}
									}
								}).setCancelable(false).show();
				break;
			case MSG_QUARANTINE_UPDATE_ERROR:
				String errMsg1 = "";
				if (msg == null || msg.obj.toString().equals("")) {
					errMsg = "서버와의 연결에 실패하였습니다.";
				} else {
					errMsg = msg.obj.toString();
				}

				myapp.utilm.ShowDialog(context, "실패", errMsg1, 20);

				break;
			default:
				break;
			}
		}
	};

	class DisinfectionDetailListAdapter extends BaseAdapter {
		CheckBox chkEdit;
		TextView txtRecNo, txtResNo, txtDsnName, txtInOut, txtDocument;
		TextView txtProdSeq, txtProdName, txtInsCnt, txtAntCnt;
		EditText editProdCnt;

		@Override
		public int getCount() {
			return prodArrList.size();
		}

		@Override
		public Object getItem(int position) {
			return prodArrList.get(position);
		}

		@Override
		public long getItemId(int position) {
			return position;
		}

		@Override
		public View getView(final int position, View convertView,
				ViewGroup parent) {
			if (convertView == null || convertView != null) {
				LayoutInflater inflater = (LayoutInflater) context
						.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
				convertView = inflater.inflate(R.layout.list_dis_detail_item,
						parent, false);
			}

			chkEdit = (CheckBox) convertView.findViewById(R.id.chk_edit);
			txtRecNo = (TextView) convertView.findViewById(R.id.detail_rec_no);
			txtResNo = (TextView) convertView.findViewById(R.id.detail_res_no);
			txtDsnName = (TextView) convertView.findViewById(R.id.detail_dsn_name);
			txtInOut = (TextView) convertView.findViewById(R.id.detail_in_out);
			txtProdSeq = (TextView) convertView.findViewById(R.id.detail_prod_seq);
			txtProdName = (TextView) convertView.findViewById(R.id.detail_prod_name);
			txtInsCnt = (TextView) convertView.findViewById(R.id.detail_ins_cnt);
			txtAntCnt = (TextView) convertView.findViewById(R.id.detail_ant_cnt);
			editProdCnt = (EditText) convertView.findViewById(R.id.detail_prod_cnt);
			txtDocument = (TextView) convertView.findViewById(R.id.detail_document);

			txtRecNo.setText(prodArrList.get(position).getRecNo());
			if (!prodArrList.get(position).getDsnfResOffCd().equals("")) {
				txtResNo.setText(prodArrList.get(position).getDsnfResOffCd()
						+ "-" + prodArrList.get(position).getDsnfResNo());
			}
			txtDsnName.setText(prodArrList.get(position).getDsnfTyName());
			txtInOut.setText(prodArrList.get(position).getVenNm());
			txtProdSeq.setText(prodArrList.get(position).getRecSeq());
			txtProdName.setText(prodArrList.get(position).getPrdlstName());
			txtInsCnt.setText(prodArrList.get(position).getInsQty());
			editProdCnt.setText(prodArrList.get(position).getAntQty());
			txtAntCnt.setText(prodArrList.get(position).getQunNm());

			if (selectedArr.contains(position)) {
				chkEdit.setChecked(true);
			} else {
				chkEdit.setChecked(false);
			}

			editProdCnt.addTextChangedListener(new TextWatcher() {
				@Override
				public void onTextChanged(CharSequence s, int start,
						int before, int count) {
				}
				@Override
				public void beforeTextChanged(CharSequence s, int start,
						int count, int after) {
				}
				@Override
				public void afterTextChanged(Editable s) {
					prodArrList.get(position).setAntQty(s.toString());
				}
			});

			chkEdit.setOnCheckedChangeListener(new OnCheckedChangeListener() {
				@Override
				public void onCheckedChanged(CompoundButton buttonView,
						boolean isChecked) {
					if (isChecked) {
						selectedArr.add(position);
					} else {
						if (selectedArr.contains(position)) {
							selectedArr.remove(selectedArr.indexOf(position));
						}
					}
				}
			});
			chkEdit.setChecked(true);

			convertView.setOnClickListener(new OnClickListener() {

				@Override
				public void onClick(View v) {
					listItemClickEvent(position);
				}
			});

			return convertView;
		}

		private void listItemClickEvent(final int position) {
		}
	}

	@Override
	public void onItemSelected(AdapterView<?> parent, View view, int position,
			long id) {
		switch (parent.getId()) {
		case R.id.content_6_1:
			disfecResultItem.setAntMetCd(antArrList.get(position).getCode());
			System.out.println("itemsel ->"+antArrList.get(position).getCode());
			break;

		case R.id.content_7_1:
			disfecResultItem.setEquKind(equArrList.get(position).getCode());
			System.out.println("itemsel ->"+equArrList.get(position).getCode());
			break;

		case R.id.content_8_1:
			disfecResultItem.setMedCd(medArrList.get(position).getCode());
			System.out.println("itemsel ->"+medArrList.get(position).getCode());
			break;
		default:
			break;
		}
	}

	@Override
	public void onNothingSelected(AdapterView<?> parent) {
	}

	@Override
	public void Onback() {
	}

	@Override
	public void OnDisinfectionResultUpdateCompleted(
			boolean isNetworkConntected, String result, String dnsfResNo, String message) {
		Log.i("message-->", "message-->"+message);
		if(null != message && !"".equals(message)){
			mResult = message;
			reesultToast();
		}
		if (myapp.dialog != null && myapp.dialog.isShowing()) {
			myapp.dialog.dismiss();
		}

		if (!isNetworkConntected) { // 네트워크 접속이 되어 있지 않을 때
			Message msg = handler.obtainMessage();
			msg.what = MSG_NETWORK_ERROR;
			handler.sendMessage(msg);
			return;
		}

		if (!result.equals("")) {
			this.success = result;
			this.dnsfResNo = dnsfResNo;
			Message msg = handler.obtainMessage();
			msg.what = MSG_QUARANTINE_UPDATE_COMPLETED;
			handler.sendMessage(msg);
		}

	}

	@Override
	public void OnDisinfectionResultUpdatelError(ErrorItem errorItem) {
		if (myapp.dialog != null && myapp.dialog.isShowing()) {
			myapp.dialog.dismiss();
		}

		Message msg = handler.obtainMessage();
		msg.what = MSG_QUARANTINE_UPDATE_ERROR;
		if (errorItem != null) {
			msg.obj = errorItem.getrDesc();
		}
		handler.sendMessage(msg);

	}

	@Override
	public void onActivityResult(int requestCode, int resultCode, Intent data) {
		super.onActivityResult(requestCode, resultCode, data);
		switch (requestCode) {
		case 1:
			if (resultCode == 1) {
				content13_1.setText(data.getStringExtra("userNm"));
				disfecResultItem.setOpeNamCd1(data.getStringExtra("userSn"));
			} else {
				Log.i("resultCode", "resultCode  0 아님");
			}
			break;

		case 2:
			if (resultCode == 1) {
				content12_1.setText(data.getStringExtra("userNm"));
				disfecResultItem.setMedNamCd1(data.getStringExtra("userSn"));
			} else {
				Log.i("resultCode", "resultCode  0 아님");
			}
			break;

		case 3:
			if (resultCode == 1) {
				content12_2.setText(data.getStringExtra("userNm"));
				disfecResultItem.setMedNamCd2(data.getStringExtra("userSn"));
			} else {
				Log.i("resultCode", "resultCode  0 아님");
			}
			break;

		case 4:
			if (resultCode == 1) {
				content1_1.setText(data.getStringExtra("venCd"));
				content1_2.setText(data.getStringExtra("cprNm"));
			} else {
			}
			break;

		case 5:
			if (resultCode == 1) {
				content13_2.setText(data.getStringExtra("userNm"));
				disfecResultItem.setOpeNamCd2(data.getStringExtra("userSn"));
			} else {
				Log.i("resultCode", "resultCode  0 아님");
			}
			break;
			
		case 6:
			BitmapFactory.Options options = new BitmapFactory.Options();
			options.inSampleSize = 4;
			Bitmap captureBmp = BitmapFactory.decodeFile("/sdcard/image.jpg", options);
			if(captureBmp != null){
				Bitmap resized = Bitmap.createScaledBitmap(captureBmp, 740, 420, true);
				
				Matrix m = new Matrix();
				m.setRotate(90, (float) resized.getWidth() / 2, (float) resized.getHeight() / 2 );
				try{
					Bitmap b2 = Bitmap.createBitmap(resized, 0, 0, resized.getWidth(), resized.getHeight(), m, true);
					if(resized != b2){
						resized.recycle();
					}
					resized = b2;
				}catch (OutOfMemoryError ex){
				
				}
				
				detail_layout13_1.setVisibility(View.VISIBLE);
				photo_check_mgs.setVisibility(View.GONE);
				if(photo_view.getDrawable() == null){
					photo_view.setVisibility(View.VISIBLE);
					button_13_1.setVisibility(View.VISIBLE);
					System.out.println("비트맵 싸이즈->"+resized.getWidth());
					System.out.println("비트맵 싸이즈->"+resized.getHeight());
					photo_view.setImageBitmap(resized);
					castString1=(myapp.cameraUtil.castByteArrayToString(myapp.cameraUtil.bitmapToByteArray(resized)));
				}else if(photo_view2.getDrawable() == null){
					photo_view2.setVisibility(View.VISIBLE);
					button_13_2.setVisibility(View.VISIBLE);
					System.out.println("비트맵 싸이즈->"+resized.getWidth());
					System.out.println("비트맵 싸이즈->"+resized.getHeight());
					photo_view2.setImageBitmap(resized);
					castString2=(myapp.cameraUtil.castByteArrayToString(myapp.cameraUtil.bitmapToByteArray(resized)));
				}
				
				File f = new File("/sdcard/image.jpg");
				if(f.exists())
				{
					f.delete();
				}
			}
			break;

		default:
			break;
		}
	}

	@Override
	public void onResume() {
		if (myapp.isFinishState()) {
			((Activity) context).finish();
			myapp.setFinishState(false);
		}
		if(myapp.isDataDetailLoadState()){
			myapp.startBroker(context);
			searchBtn.performClick();
			myapp.setDataDetailLoadState(false);
		}
		if(myapp.isAbleHome()){
			homeBtn.performClick();
			myapp.setAbleHome(false);
		}
		super.onResume();
	}

	@Override
	public void onPause() {
		myapp.setFinishState(false);
		super.onPause();
	}
	
	@Override
	public void onDestroyView() {
		super.onDestroyView();
		AppStatus.navigation.delPathLocation();
	}
	
	private void reesultToast() {
		am.runOnUiThread(new Runnable() {

            public void run() {
                Toast toast = Toast.makeText(context, mResult, Toast.LENGTH_SHORT);
                toast.setGravity(Gravity.CENTER, 0, 50);
                toast.show();
            }
        });
    }

}
